<?php
/**
 *  This file is part of CI-ActiveRecord
 *
 *  CI-ActiveRecord is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  CI-ActiveRecord is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with CI-ActiveRecord.  If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * ActiveRecord_Exception
 * Provide a custom Exception
 */
class ActiveRecord_Exception extends Exception 
{ 
    private $_errorMessages = array(
        ActiveRecord::ERR                       => 'unknown error',
        ActiveRecord::ERR_UNDEFINED_METHOD      => 'undefined method',
        ActiveRecord::ERR_UNDEFINED_PROPERTY    => 'undefined property',
        ActiveRecord::ERR_INVALID_DATA          => 'invalid data',
        ActiveRecord::ERR_RECORD_IS_TRANSIENT   => 'record is transient',
        ActiveRecord::ERR_UNKOWN_BEHAVIOUR      => 'unknown behaviour',
        ActiveRecord::ERR_INVALID_BEHAVIOUR     => 'invalid behaviour',
        ActiveRecord::ERR_UNKOWN_VALIDATOR      => 'unknown validator',
        ActiveRecord::ERR_INVALID_VALIDAOR      => 'invalid validator',
        ActiveRecord::ERR_CANNOT_SAVE           => 'con not save record',
        ActiveRecord::ERR_CANNOT_UPDATE         => 'can not update record',
        ActiveRecord::ERR_CANNOT_DELETE         => 'can not delete record',
        ActiveRecord::ERR_CANNOT_DELETEALL      => 'can not delete all records',
        ActiveRecord::ERR_UNKOWN_STATE          => 'unknown record state');
        
    public function __construct($err)
    {
        if ( ! array_key_exists($err, $this->_errorMessages)) {
            $err = ActiveRecord::ERR;
        }
        
        parent::__construct($this->_errorMessages[$err], $err);
    }
}